//
//  FindPassWordViewController.m
//  IFengNews
//
//  Created by lanou3g on 16/3/7.
//  Copyright © 2016年 徐强. All rights reserved.
//

#import "FindPassWordViewController.h"

@interface FindPassWordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userName;


@end

@implementation FindPassWordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (IBAction)sendNewPassWord:(id)sender {
    
    NSUserDefaults *use = [NSUserDefaults standardUserDefaults];
    if([use objectForKey:self.userName.text]!= nil)
    {
        //说明有这个账户的信息
        NSString *str = [NSString stringWithFormat:@"%d%d%d%d%d%d",arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10,arc4random() % 10];
        [use setValue:str forKey:self.userName.text];
        //str记录重置密码，弹出重置密码并直接返回登陆界面
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"密码重置为：%@",str] preferredStyle:(UIAlertControllerStyleAlert)];
        [self presentViewController:alert animated:YES completion:^{
            sleep(5);
            [self dismissViewControllerAnimated:YES completion:^{
                [self dismissViewControllerAnimated:YES completion:nil];
            }];
        }];
    }
    else
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"该账户并未注册" preferredStyle:(UIAlertControllerStyleAlert)];
        [self presentViewController:alert animated:YES completion:^{
            sleep(2);
            [self dismissViewControllerAnimated:YES completion:nil];
        }];
    }
}
//点击空白处回收键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
//返回登陆界面
- (IBAction)escFindPassWord:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}


@end
